package com.yxjwzpx.management.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.yxjwzpx.management.domain.RepairCost;
import com.yxjwzpx.management.service.IRepairCostService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 维修成本Controller
 * 
 * @author yxjwzpx
 * @date 2025-04-09
 */
@RestController
@RequestMapping("/management/cost")
public class RepairCostController extends BaseController
{
    @Autowired
    private IRepairCostService repairCostService;

    /**
     * 查询维修成本列表
     */
    @PreAuthorize("@ss.hasPermi('management:cost:list')")
    @GetMapping("/list")
    public TableDataInfo list(RepairCost repairCost)
    {
        startPage();
        List<RepairCost> list = repairCostService.selectRepairCostList(repairCost);
        return getDataTable(list);
    }

    /**
     * 导出维修成本列表
     */
    @PreAuthorize("@ss.hasPermi('management:cost:export')")
    @Log(title = "维修成本", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RepairCost repairCost)
    {
        List<RepairCost> list = repairCostService.selectRepairCostList(repairCost);
        ExcelUtil<RepairCost> util = new ExcelUtil<RepairCost>(RepairCost.class);
        util.exportExcel(response, list, "维修成本数据");
    }

    /**
     * 获取维修成本详细信息
     */
    @PreAuthorize("@ss.hasPermi('management:cost:query')")
    @GetMapping(value = "/{costId}")
    public AjaxResult getInfo(@PathVariable("costId") Long costId)
    {
        return success(repairCostService.selectRepairCostByCostId(costId));
    }

    /**
     * 新增维修成本
     */
    @PreAuthorize("@ss.hasPermi('management:cost:add')")
    @Log(title = "维修成本", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RepairCost repairCost)
    {
        return toAjax(repairCostService.insertRepairCost(repairCost));
    }

    /**
     * 修改维修成本
     */
    @PreAuthorize("@ss.hasPermi('management:cost:edit')")
    @Log(title = "维修成本", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RepairCost repairCost)
    {
        return toAjax(repairCostService.updateRepairCost(repairCost));
    }

    /**
     * 删除维修成本
     */
    @PreAuthorize("@ss.hasPermi('management:cost:remove')")
    @Log(title = "维修成本", businessType = BusinessType.DELETE)
	@DeleteMapping("/{costIds}")
    public AjaxResult remove(@PathVariable Long[] costIds)
    {
        return toAjax(repairCostService.deleteRepairCostByCostIds(costIds));
    }
}
